package cn.tedu.weibo.controller;

import cn.tedu.weibo.common.response.JsonResult;
import cn.tedu.weibo.pojo.dto.UserRegDTO;
import cn.tedu.weibo.pojo.dto.UserLoginDTO;
import cn.tedu.weibo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/v1/users/")
public class UserController {
    @Autowired
    IUserService userService;
    @PostMapping("reg")
    public JsonResult reg(@RequestBody UserRegDTO userRegDTO){

        userService.reg(userRegDTO);

        return JsonResult.ok();
    }
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginDTO LoginDTO){
        //把登录成功的当事人响应给客户端
        return JsonResult.ok(userService.login(LoginDTO));
    }

    @GetMapping("logout")
    public JsonResult logout(){
        userService.logout();

        return JsonResult.ok();
    }


}

